<template>
  <view>
    <u-table width="100%" border-color="#214423" bg-color="#214423" :th-style="{color:'#FF0080',}" color="#fff">
      <u-tr>
        <u-th width="30%" nowrap="nowrap">物品名称</u-th>
        <u-th nowrap="nowrap">库室</u-th>
        <u-th nowrap="nowrap">申请人</u-th>
        <u-th nowrap="nowrap">状态</u-th>
      </u-tr>
      <u-tr v-for="(item,index) of lists" :key="index">
        <u-td><text :class="item.status==true?'danger':''">{{item.hb_rock_zhuang_ru_ku_name}}</text></u-td>
        <u-td><text :class="item.status==true?'danger':''">{{item.hb_rock_ku_shi_name}}</text></u-td>
        <u-td><text :class="item.status==true?'danger':''">{{item.user_name}}</text></u-td>
        <u-td><text :class="item.status==true?'danger':''">{{item.sta}}</text></u-td>
      </u-tr>
    </u-table>
    	<u-toast ref="uToast" />
  </view>
</template>

<script>
  const sdkwx = uni.requireNativePlugin('GGRfid-SdkWX');
  import sqlLite from '../../common/sqllite-utils.js';
  export default {
    data() {
      return {
        RFID:'',
        border:true,
        lists:[]
      }
    },
    onReady() {
      this.$refs.uToast.show({
        title: '开启扫描成功',
        type: 'success',
      });
      const readerName = '/dev/ttysWK0:115200';
      const packageSize = 64;
      const freeWait = 100;
      const power = 15;
      
      sdkwx.open(readerName, packageSize, freeWait, power);
      const that = this;
      // 设置回调事件
      sdkwx.setTagEpcCallback((res) => {
        that.RFID = res.log.epc;
        this.searchRfidInfo()
      });
    },
    onUnload() {
      sdkwx.close();
    },
    methods: {
      searchRfidInfo() {
        const tableName = 'equipmentMaintenancetables';
        sqlLite.selectFromTable(
                 	`select * from ${tableName} where rfid='${this.RFID}'`,
        ).then(res => {
          if(res.length === 0) {
            this.$refs.uToast.show({
              title: '当前该rfid没有相应的维修信息',
              type: 'success',
            });
          }
          this.lists = res
        }).catch(err => {
          console.log(err,'查找到的装备维修表失败回调')
        })
      }
    }
  }
</script>

<style>

</style>
